﻿@using Website.CRUDServices
@using Location = Website.Models.Domain.Location
@using Profile = Website.Models.Domain.Profile
@using Region = Website.Models.Domain.Region
@{
    this.ViewBag.Title = "Opdatér Projektmøde";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var Presentations = this.ViewData["Presentations"] as List<Presentation>;
    var Regions = this.ViewData["Regions"] as List<Region>;
    var Projects = this.ViewData["Projects"] as List<Project>;
    var Demonstrations = this.ViewData["Demonstrations"] as List<ProjectMeetingDemonstration>;
    var Funds = this.ViewData["Funds"] as List<Fund>;
    var Types = this.ViewData["Types"] as List<ProjectType>;
    var Roles = this.ViewData["Roles"] as List<ProjectMeetingRole>;
    var Groups = this.ViewData["Groups"] as List<Group>;
    var Profiles = this.ViewData["Profiles"] as Website.Models.ViewModels.ProfilesView;
    var Project = Model as ProjectMeeting;
    Guid otherId = Guid.Empty;

    // errorhandling
    var errorMsg = new HtmlString(string.Empty);
    if (this.ViewData["ErrorMessage"] != null)
    {
        errorMsg = this.ViewData["ErrorMessage"] as HtmlString;
    }
    bool? isRandD = null;
    if (Types.Any(x => x.ID == Project.Status.Type))
    {
        isRandD = Types.Single(x => x.ID == Project.Status.Type).IsResearchAndDevelopment;
    }
}

@Html.Partial("~/Views/_Shared/LogView.cshtml", Project.ID)

<script type="text/javascript">
    //toggle script
    function toggle(id) {
        var allFields = new Array('NotStarted', 'Started', 'Completed');
        for (var i = 0; i < allFields.length; i++) {
            document.getElementById(allFields[i]).style.display = 'none';
        }

        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }

    function toggleRD(id) {
        var allFields = new Array('RAndD', 'NotRAndD');
        for (var i = 0; i < allFields.length; i++) {
            document.getElementById(allFields[i]).style.display = 'none';
        }

        if (document.getElementById(id).style.display == 'none' || document.getElementById(id).style.display == "") {
            document.getElementById(id).style.display = 'block';
        } else {
            document.getElementById(id).style.display = 'none';
        }
    }
</script>
<script>
    $(function () {
        $("#datepicker").datepicker();
        @if (Project.Status.StatusType == ProjectMeetingStatusType.NotStarted)
        {@Html.Raw("toggle('NotStarted');")}
        @if (Project.Status.StatusType == ProjectMeetingStatusType.Started)
        {@Html.Raw("toggle('Started');")}
        @if (Project.Status.StatusType == ProjectMeetingStatusType.Completed)
        {@Html.Raw("toggle('Completed');")}
        @if (isRandD.HasValue && !isRandD.Value)
        {@Html.Raw("toggleRD('NotRAndD')")}
        @if (isRandD.HasValue && isRandD.Value)
        {@Html.Raw("toggleRD('RAndD')")}
    });
</script>

@using (this.Html.BeginForm())
{
    <div class="error">
        @errorMsg
    </div>

    
            // name
    <div class="formBullet">Titel</div>
    <input type="text" id="Name" name="Name" value="@Project.Name"/>
    
    // ownerProjects chooser
    <div class="formBullet">Alle projekter tilknyttet</div>
    <div class="formEntry">
        <select multiple="multiple" name="OwnerProjects" id="OwnerProjects">
            @foreach (Project proj in Projects.Where(x => (Project.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@proj.ID" selected="selected">@proj.Name</option>
            }
            @foreach (Project proj in Projects.Where(x => !(Project.OwnerProjects ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@proj.ID">@proj.Name</option>
            }
        </select>
    </div>


            // date
    <div class="formBullet">Dato</div>
    <input type="text" id="datepicker" name="Date" readonly="readonly" value="@Project.Date" />

            // location
    <div class="formBullet">Lokation</div>
    <div class="formEntry">
        <select name="Location" id="Location">
            <option value="@Guid.Empty">Vælg en lokation</option>
            @foreach (Location loc in Profiles.Locations.OrderBy(x => x.Name))
            {
                if (loc.ID == Project.LocationID)
                {
                <option value="@loc.ID" selected="selected">@loc.Name</option>
                }
                else
                {
                <option value="@loc.ID">@loc.Name</option>
                }
            }
        </select>
    </div>

            // national or international?
    <div class="formBullet">Nationalt?</div>
    <div>
        <input type="radio" name="IsNational" value="National"@if (Project.IsNational)
                                                              {@Html.Raw(" checked=\"checked\"")} />Nationalt
        <input type="radio" name="IsNational" value="International"@if (!Project.IsNational)
                                                                   {@Html.Raw(" checked=\"checked\"")} />Internationalt
    </div>
                                                                   // profiles chooser
    <div class="formBullet">Deltagere</div>
    <div class="formEntry">
        <select multiple="multiple" name="Participants" id="Participants">
            @foreach (Profile prof in Profiles.Profiles.Where(x => (Project.Participants ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@prof.ID" selected="selected">@prof.Name</option>
            }
            @foreach (Profile prof in Profiles.Profiles.Where(x => !(Project.Participants ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@prof.ID">@prof.Name</option>
            }
        </select>
    </div>

            // Groups chooser
 @*   <div class="formBullet">Grupper</div>
    <div class="formEntry">
        <select multiple="multiple" name="Groups" id="Groups">
            @foreach (Group group in Groups.Where(x => (Project.Groups ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@group.ID" selected="selected">@group.Name</option>
            }
            @foreach (Group group in Groups.Where(x => !(Project.Groups ?? new Guid[0]).Contains(x.ID)))
            {
                <option value="@group.ID">@group.Name</option>
            }
        </select>
    </div>
 *@
            // ********************StatusSelector*********************
    <div class="formBullet">Projektets status</div>
    <div>
        <label>
            <input type="radio" name="ProjectStatusType" value="SwitchStatusNotStarted" onclick=" toggle('NotStarted'); " 
                @if (Project.Status.StatusType == ProjectMeetingStatusType.NotStarted)
                                                                                                                   {@Html.Raw("checked")}>Ikke startet</label>
        <label>
            <input type="radio" name="ProjectStatusType" value="SwitchStatusStarted" onclick=" toggle('Started'); " @if (Project.Status.StatusType == ProjectMeetingStatusType.Started)
                                                                                                             {@Html.Raw("checked")}>Startet</label>
        <label>
            <input type="radio" name="ProjectStatusType" value="SwitchStatusCompleted" onclick=" toggle('Completed'); " @if (Project.Status.StatusType == ProjectMeetingStatusType.Completed)
                                                                                                                 {@Html.Raw("checked")}>Færdigt</label>
    </div>
                                                                                                                 // ********************ProjectMeetingStatus*********************
                                                                                                                 // ********************ProjectMeetingStatus*********************
    <div class="formEntry open_hidden" id="NotStarted">
        <br />
        <fieldset class="chosenFields">
            <legend>Ikke startet</legend>
            <!--demonstration chooser -->
            <div class="formBullet">Vejledt om</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.FundsGuidance" id="StatusNotStartedFundsGuidance">
                    @foreach (Fund prof in Funds.Where(x => (Project.Status.GuidanceAbout ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (Fund prof in Funds.Where(x => !(Project.Status.GuidanceAbout ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>
            <!--guidance comments -->
            <div class="formBullet">Kommentarer til vejledning</div>
            <textarea id="StatusNotStartedGuidanceText" name="ProjectMeetingStatus.GuidanceText">@Project.Status.GuidanceAboutText</textarea>

            <!--demonstration chooser -->
            <div class="formBullet">Ansøgninger til</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.FundsApplication" id="StatusNotStartedFundsApplication">
                    @foreach (Fund prof in Funds.Where(x => (Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (Fund prof in Funds.Where(x => !(Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>
            <!--application comments-->
            <div class="formBullet">Kommentarer til ansøgning</div>
            <textarea id="StatusNotStartedApplicationText" name="ProjectMeetingStatus.ApplicationText">@Project.Status.FinancingText</textarea>

            <!--demonstration chooser -->
            <div class="formBullet">Aktivitet</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.InnovationAndIdeas" id="StatusNotStartedInnovationAndIdeas">
                    @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => (Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => !(Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>
        </fieldset>
    </div>

                    // ********************StatusStarted*********************
    <div class="formEntry open_hidden" id="Started">
        <br />
        <fieldset class="chosenFields">
            <legend>Startet</legend>
            <!--roles chooser -->
            <div class="formBullet">Roller</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.Roles" id="StatusStartedRoles">
                    @foreach (ProjectMeetingRole prof in Roles.Where(x => (Project.Status.Roles ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (ProjectMeetingRole prof in Roles.Where(x => !(Project.Status.Roles ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>

            <!--financing chooser -->
            <div class="formBullet">Financiering</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.Financing" id="StatusStartedFinancing">
                    @foreach (Fund prof in Funds.Where(x => (Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (Fund prof in Funds.Where(x => !(Project.Status.Financing ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>
            <!--More Information -->
            <div class="formBullet">Yderligere information om financiering</div>
            <textarea id="StatusStartedFinancingComments" name="ProjectMeetingStatus.FinancingComments">@Project.Status.FinancingText</textarea>

        </fieldset>
    </div>

                    // ********************StatusCompleted*********************
    <div class="formEntry open_hidden" id="Completed">
        <br />
        <fieldset class="chosenFields">
            <legend>Færdigt</legend>

            <!--demonstration chooser -->
            <div class="formBullet">Gennemførte ting</div>
            <div class="formEntry">
                <select multiple="multiple" name="ProjectMeetingStatus.Demonstration" id="StatusCompletedDemonstration">
                    @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => (Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID" selected="selected">@prof.Name</option>
                    }
                    @foreach (ProjectMeetingDemonstration prof in Demonstrations.Where(x => !(Project.Status.DemonstrationIDs ?? new Guid[0]).Contains(x.ID)))
                    {
                        <option value="@prof.ID">@prof.Name</option>
                    }
                </select>
            </div>
        </fieldset>
    </div>

                    // ********************R&D chooser*********************    
    <div class="formBullet">R&D type</div>
    <div>
        <label>
            <input type="radio" name="StatusType" value="SwitchStatusNotRAndD" onclick=" toggleRD('NotRAndD'); "  @if (isRandD.HasValue && !isRandD.Value)
                                                                                                                  {@Html.Raw("checked=\"checked\"")}>Non R&D</label>
        <label>
            <input type="radio" name="StatusType" value="SwitchStatusRAndD" onclick=" toggleRD('RAndD'); "  @if (isRandD.HasValue && isRandD.Value)
                                                                                                            {@Html.Raw("checked=\"checked\"")}>R&D</label>
    </div>

                                                                                                            // ********************StatusNotRAndD*********************
    <div class="formEntry open_hidden" id="NotRAndD">
        <br />
        <fieldset class="chosenFields">
            <legend>Non R&D</legend>
            <!--project type -->
            <div class="formBullet">Projekt Type</div>
            <div class="formEntry">
                <select name="StatusNotRAndD.Type" id="StatusNotRAndDType">
                    @foreach (ProjectType ty in Types.Where(x => x.IsResearchAndDevelopment == false))
                    {
                        if (ty.ID == Project.Status.Type)
                        {
                        <option value="@ty.ID" selected="selected">@ty.Name</option>
                        }
                        else
                        {
                        <option value="@ty.ID">@ty.Name</option>
                        }
                    }
                </select>
            </div>
            <!--More Information -->
            <div class="formBullet">Yderligere information</div>
            <textarea id="StatusNotRAndDMoreInformation" name="StatusNotRAndD.MoreInformation">@if(isRandD.HasValue && !isRandD.Value){@Project.Status.Description}</textarea>

        </fieldset>
    </div>

                    // ********************StatusRAndD*********************
    <div class="formEntry open_hidden" id="RAndD">
        <br />
        <fieldset class="chosenFields">
            <legend>R&D</legend>
            <!--project type -->
            <div class="formBullet">Projekt Type</div>
            <div class="formEntry">
                <select name="StatusRAndD.Type" id="StatusRAndDType">
                    @foreach (ProjectType ty in Types.Where(x => x.IsResearchAndDevelopment))
                    {
                        if (ty.ID == Project.Status.Type)
                        {
                        <option value="@ty.ID" selected="selected">@ty.Name</option>
                        }
                        else
                        {
                        <option value="@ty.ID">@ty.Name</option>
                        }
                    }
                </select>
            </div>
            <!--More Information -->
            <div class="formBullet">Yderligere information</div>
            <textarea id="StatusRAndDMoreInformation" name="StatusRAndD.MoreInformation">@if(isRandD.HasValue && isRandD.Value){@Project.Status.Description}</textarea>
        </fieldset>
    </div>

                    // ********************StatusPatents*********************
    <div class="formEntry" id="Patents">

        <!--patent name -->
        <div class="formBullet">Patent navn</div>
        <input type="text" id="StatusPatentsPatentName" name="StatusPatents.PatentName" value="@Project.Status.PatentName" />
    </div>

    // ********************Submit*********************
    <div class="buttonHolder">
        <script type="text/javascript">
            function confirmDelete() {
                if (confirm("Er du sikker på at du vil slette aktiviteten? Dette valg kan ikke fortrydes.")) {
                    location.href = '@this.Url.Action("DeleteProjectMeeting", new { ID = Project.ID })';
                 }
             }
        </script>
            <input type="button" value="Slet" class="deleteButton margin-right-20" 
                 onclick="confirmDelete();"
                />
        <input type="submit" value="Opdatér" />
    </div>
}


<script>

    $(function () {
        $('#StatusNotStartedFundsGuidance').multiSelect();
        $('#StatusNotStartedFundsApplication').multiSelect();
        $('#StatusNotStartedInnovationAndIdeas').multiSelect();
        $('#Participants').multiSelect();
        $('#StatusStartedRoles').multiSelect();
        $('#StatusStartedFinancing').multiSelect();
        $('#StatusCompletedDemonstration').multiSelect();
        $('#Groups').multiSelect();
        $('#OwnerProjects').multiSelect();

       
    });
</script>